import json

from jsonpath import jsonpath

from tools.env_class import Env_Var
from loguru import logger


def exc_var(exc,resp):
    if exc is None:
        return
    elif exc is not None:
        exc = json.loads(exc)
        for k,v in exc.items():
            if v.startswith("$.."):
                value = jsonpath(resp.json(),v)[0]
                setattr(Env_Var,k,value)
            elif v == "text":
                value = resp.text
                setattr(Env_Var,k,value)
        logger.info(Env_Var.__dict__)

